<?php
/**
 * Admin扩展类
 * @author liudaiming
 * @version 2014.3.7
 *
 */
class AdminAction extends Action{
	private $_module = array('Setting');
	private $_action = array('upload','uploadimg');
	
	/**
	 * init
	 */
	public function _initialize(){
		$this->check_login();
		$this->check_role();
		$js_file = Resource::getStatic(array('jquery','common'),'js');
		$css_file = Resource::getStatic('admin');
		$this->assign('css_file',$css_file);
		$this->assign('js_file',$js_file);
	}
	/**
	 * 判断是否登录
	 */
	final public function check_login(){
		$userid = Session('dis_userid');
		$module = MODULE_NAME;
		$action = ACTION_NAME;
		$sessionid = I('PHPSESSID');
		if(in_array($action,$this->_action)){
			return true;
		}
		if (empty($userid)){
			if(!in_array($action,$this->_action)){
				$this->error('您尚未登录，请先登录','/Admin/Public/login');
			}
		}
	}
	/**
	 * 检查操作权限
	 */
	final public function check_role(){
		$roleid = (int)session('dis_role');
		$group = GROUP_NAME;
		$module = MODULE_NAME;
		$action = ACTION_NAME;
		if(in_array($action,$this->_action)){
			return true;
		}
		if(($group=='Admin')&&($module=='Index')&&($action=='index'||$action=='top'||$action=='menu'||$action=='main'||$action=='logout')){
			return true;
		}
		if(session('dis_role')==1){
			return true;
		}
		$priModel = M('AdminPriv');
		$where = array('role_id'=>$roleid,'m'=>$group,'c'=>$module,'a'=>$action);
		$res = $priModel->where($where)->find();
		if(empty($res)){
			$this->assign("jumpUrl", U('/Admin/Index/main'));
			$this->error('您没有此项操作权限');
		}
		
	}
	
}